<?php
declare (strict_types = 1);

namespace app\admin\validate;

use think\Validate;

class OrderPayment extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'order_id'         => 'require|integer',
        'payment_method'   => 'require|max:2',
        'payment_method_name' => 'max:50',
        'pay_type'         => 'require|max:2',
        'pay_account'      => 'max:255',
        'pay_time'         => 'date',
        'pay_amount'       => 'require|float',
        'voucher_code'     => 'require|max:128',
        'creator'          => 'integer',
        'create_time'      => 'date',
        'reviewer'         => 'integer',
        'reviewer_time'    => 'date',
        'transfer_voucher_id' => 'integer',
        'status'           => 'require|max:2',
        'notes'            => 'max:255',
        'order_type'       => 'max:10',
        'order_no'         => 'max:100',
        'user_id'          => 'integer',
        'pay_code'         => 'max:50',
        'pay_currency'     => 'integer',
        'payment_url'      => 'max:255',
        'id' => 'integer|require',
        'order_type' => 'require|max:10',
        'voucher_id' => 'require|array',
        'paid_amount' => 'require|float',
        'fee_type' => 'require|float',    // 费用类型 1: 订单费用  2: 物流费用补充（无关订单状态）
    ];

    // 定义错误信息
    protected $message = [
        'order_id.require' => '订单ID必须',
        'order_id.integer' => '订单ID必须是整数',
        'payment_method.require' => '支付方式ID必须',
        'payment_method.max' => '支付方式ID最多2个字符',
        'pay_type.require' => '支付类型必须',
        'pay_type.max' => '支付类型最多2个字符',
        'pay_amount.require' => '支付金额必须',
        'pay_amount.float' => '支付金额必须是浮点数',
        'status.require' => '状态必须',
        'status.max' => '状态最多2个字符',
        'order_type' => '订单类型必须',
        'voucher_id.require' => '凭证不能为空',
        'voucher_id.integer' => '凭证参数错误',
        'voucher_code.require' => '交易单号不能为空',
        'voucher_code.max' => '交易单号最多50个字符',
        'paid_amount.require' => '支付金额不能为空',
        'paid_amount.float' => '支付金额必须是浮点数',
        'fee_type.require' => '费用类型不能为空',
        'fee_type.integer' => '费用类型必须是整数',
    ];

    // 场景定义
    protected $scene = [
        'add' => ['order_id', 'payment_method', 'pay_type', 'pay_amount', 'status'],
        'examine' => ['id','paid_amount'],
        'cancel' => ['id'],
        'search' => ['voucher_code'=>'max:256'],
        'voucher' => ['order_id','order_type','voucher_id','voucher_code','paid_amount','fee_type'],
        'order_related_payment_list' => ['order_id'],
    ];
}
